package com.lerarneurekacheckinvoke.eurekacheckinvoke.common

import feign.Feign
import okhttp3.ConnectionPool
import okhttp3.OkHttpClient
import org.springframework.boot.autoconfigure.AutoConfigureBefore
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import java.util.concurrent.TimeUnit

@Configuration
@ConditionalOnClass((Feign::class))
@AutoConfigureBefore((OkHttpClient::class))
class okHttp {
    @Bean
     fun okHttpClient(): OkHttpClient {
         var builder= OkHttpClient.Builder()
        builder.connectTimeout(60, TimeUnit.SECONDS)
                //读超时时间
                .readTimeout(60, TimeUnit.SECONDS)
                //写超时时间
                .writeTimeout(60, TimeUnit.SECONDS)
                //是否自动连接
                .retryOnConnectionFailure(true)
                .connectionPool(ConnectionPool())
        return builder.build()
    }
}